package com.mingqi.enetconnected.util;

import java.text.DecimalFormat;

/**
 * @author yaxi
 * @date 2018/9/17
 */
public class AmountTranslateUtil {


    /**
     * 将圆转为分
     * @return
     */
    public static int transformAmount(double yuan){
        return (int) (yuan*100);
    }

    /**
     * 将分转为圆
     * @return
     */
    public static double transformAmount(int fen){
        return (double) fen / 100;
    }

    /**
     * 添加前缀￥并保持两位小数
     * @param yuan
     * @return
     */
    public static String decorate(double yuan){
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        return "￥" + decimalFormat.format(yuan);
    }

    /**
     * 移除￥并转成double
     * @param yuan
     * @return
     */
    public static double unDecorate(String yuan){
        String substring = yuan.substring(1);
        return Double.parseDouble(substring);
    }


}
